package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ClassificationofdoctorsBean;
import com.example.myapplication.ShuJu.PetclassificationBean;
import com.example.myapplication.hospital.ConsultationpageActivity;
import com.example.myapplication.hospital.MedicActivity;
import com.google.gson.Gson;

import java.util.List;

public class ClassificationofdoctorsApter extends  RecyclerView.Adapter<ClassificationofdoctorsApter.Myhot>{
    private Context context;
    private List<ClassificationofdoctorsBean.RowsBean> list;

    public ClassificationofdoctorsApter(Context context, List<ClassificationofdoctorsBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ClassificationofdoctorsApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_classificationofdoctors, null);
        return new ClassificationofdoctorsApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ClassificationofdoctorsApter.Myhot holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getAvatar()).into(holder.img);
        holder.name.setText(list.get(position).getName());
        holder.jobName.setText(list.get(position).getJobName());
        holder.practiceNo.setText(list.get(position).getPracticeNo());
        int length = list.get(position).getGoodAt().length();
        if(length >15 && !TextUtils.isEmpty( list.get(position).getGoodAt())){
            holder.goodAt.setText(list.get(position).getGoodAt().substring(0,15)+"...");
        }else{
            holder.goodAt.setText(list.get(position).getGoodAt());
        }

        holder.workingYears.setText(String.valueOf(list.get(position).getWorkingYears()));
        //问诊页面
        holder.re_medic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ConsultationpageActivity.class);
                Gson gson = new Gson();
                String BeanJSON = gson.toJson(list.get(position));
                intent.putExtra(Commom.CONSULTATIONPAGE_ID,BeanJSON);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView name;
        private final ImageView img;
        private final TextView jobName;
        private final TextView practiceNo;
        private final TextView workingYears;
        private final TextView goodAt;
        private final RelativeLayout re_medic;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            jobName = itemView.findViewById(R.id.jobName);
            practiceNo = itemView.findViewById(R.id.practiceNo);
            goodAt = itemView.findViewById(R.id.goodAt);
            workingYears = itemView.findViewById(R.id.workingYears);
            re_medic = itemView.findViewById(R.id.re_medic);
        }
    }
}

